package com.jagochan.module.rbac.sys_role_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jagochan.module.rbac.sys_role_menu.domain.SysRoleMenu;
import com.jagochan.module.rbac.sys_role_menu.mapper.SysRoleMenuMapper;
import com.jagochan.module.rbac.sys_role_menu.service.SysRoleMenuService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

    /**
     * 根据角色ID列表查询菜单ID列表
     */
    @Override
    public List<Long> listMenuIdsByRoleIds(List<Long> roleIdList) {
        List<SysRoleMenu> roleMenuList = lambdaQuery().in(SysRoleMenu::getRoleId, roleIdList).select(SysRoleMenu::getMenuId).list();
        return roleMenuList.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
    }

    @Override
    public boolean removeByRoleId(String roleId) {
        LambdaQueryWrapper<SysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysRoleMenu::getRoleId, roleId);
        return remove(wrapper);
    }
}